package top.misec;

import lombok.extern.log4j.Log4j2;
import top.misec.config.Config;
import top.misec.login.ServerVerify;
import top.misec.login.Verify;
import top.misec.task.DailyTask;
import top.misec.task.ServerPush;
import top.misec.utils.LoadFileResource;
import top.misec.utils.VersionInfo;

import java.text.ParseException;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

@Log4j2
public class BiliMain {


    public static void main(String[] args) {
        final String userId = System.getProperty("userId");
        final String sessData = System.getProperty("sessData");
        final String biliJct = System.getProperty("biliJct");
        final String push = System.getProperty("push");
        Verify.verifyInit(userId, sessData, biliJct);
        ServerVerify.verifyInit(push);
        Timer timer = new Timer();
        timer.schedule(new BiliTask(), new Date(), 1000 * 60 * 60 * 24);
    }

    private static class BiliTask extends TimerTask {
        @Override
        public void run() {
            try {
                VersionInfo.printVersionInfo();
                //每日任务65经验
                Config.getInstance().configInit();
                if (!Config.getInstance().isSkipDailyTask()) {
                    DailyTask dailyTask = new DailyTask();
                    dailyTask.doDailyTask();
                } else {
                    log.info("已开启了跳过本日任务，本日任务跳过（不会发起任何网络请求），如果需要取消跳过，请将skipDailyTask值改为false");
                    ServerPush.doServerPush();
                }
            } catch (Exception e) {
                log.error("任务执行失败!", e);
                ServerPush.doServerPush();
            } finally {
                LoadFileResource.deleteLogFile();
            }
        }
    }

}
